﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
using Cinemon.MySqlConnect;

public partial class License_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(IsPostBack == true)
        {
            int number = Int32.Parse(licenselb.Text);
            string companyname = companyNameBox.Text;
            string contact = ContactNameBox.Text;
            string email = ContactEmailBox.Text;
            string cell = ContactNumberBox.Text;
            int newD = Int32.Parse(MonthSelectionDrop.SelectedValue);

            using (DatabaseManager manager = new DatabaseManager())
            {
                List<MySqlParameter> param = new List<MySqlParameter> {
				new MySqlParameter("licenseid", number),
				new MySqlParameter("companyName", companyname),
				new MySqlParameter("contact", contact),
				new MySqlParameter("email", email),
                new MySqlParameter("cell", cell),
                new MySqlParameter("newdate", newD)
			};
                manager.ExecuteNonQuery("updateLicense", param);
            }
            Response.Redirect("view.aspx");

        }
        licenselb.Text = Request.QueryString["id"];
        using (DatabaseManager manager = new DatabaseManager())
        {
            List<MySqlParameter> param = new List<MySqlParameter> {
				new MySqlParameter("licenseid",Int32.Parse(Request.QueryString["id"]))
			};
            DataTable table = manager.ExecuteQuery("getLicenseInfo",param);
            companyNameBox.Text = table.Rows[0]["license_company"].ToString();
            ContactNameBox.Text = table.Rows[0]["license_contact"].ToString(); 
            ContactNumberBox.Text = table.Rows[0]["license_contact_cellphone"].ToString();
            ContactEmailBox.Text = table.Rows[0]["license_contact_email"].ToString();
            Expirylbl.Text = ((DateTime)table.Rows[0]["license_expiry_date"]).ToString("MM/dd/yyyy");
        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("view.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
    }
}